package com.sinosoft.ebusiness;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

//@EnableDiscoveryClient
@EnableJpaRepositories(basePackages = "com.sinosoft")
@EntityScan(basePackages = "com.sinosoft.ebusiness.domain.myproduct")
@SpringBootApplication
public class TestApplication {

	public static void main(String[] args) {
		SpringApplication.run(TestApplication.class, args);
	}
	
	@Bean
    public HibernateJpaSessionFactoryBean sessionFactory() {
        return new HibernateJpaSessionFactoryBean();
    }
	
	
	/*@Bean
    public MappingJackson2HttpMessageConverter jaksonHttpMessageConverters() {
		MappingJackson2HttpMessageConverter mapper = new MappingJackson2HttpMessageConverter();
		List<MediaType> list = new ArrayList<>();
		list.add(MediaType.APPLICATION_JSON_UTF8);
		list.add(MediaType.TEXT_XML);
		mapper.setSupportedMediaTypes(list);
		return mapper;
	}*/
	
	
	/*@Bean  
    public MappingJackson2HttpMessageConverter getMappingJackson2HttpMessageConverter() {  
        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();  
        //设置日期格式  
        ObjectMapper objectMapper = new ObjectMapper();  
        SimpleDateFormat smt = new SimpleDateFormat("yyyy-MM-dd");  
        objectMapper.setDateFormat(smt);  
        objectMapper.setSerializationInclusion(Include.NON_NULL); 
//        objectMapper.disable(DeserializationConfig.FAIL_ON_UNKNOWN_PROPERTIES);  
//        objectMapper.configure(DeserializationConfig.);
  
        objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
        mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);  
        //设置中文编码格式  
        List<MediaType> list = new ArrayList<MediaType>();  
        list.add(MediaType.APPLICATION_JSON);  
        mappingJackson2HttpMessageConverter.setSupportedMediaTypes(list); 
        return mappingJackson2HttpMessageConverter;  
    }*/
	
	
	@Bean
    public HttpMessageConverters fastJsonHttpMessageConverters() {
       FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
       FastJsonConfig fastJsonConfig = new FastJsonConfig();
       fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);//SerializerFeature.PrettyFormat,
//       fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect);//SerializerFeature.PrettyFormat,
       fastConverter.setFastJsonConfig(fastJsonConfig);
       HttpMessageConverter<?> converter = fastConverter;
       HttpMessageConverters c =  new HttpMessageConverters(converter);
       return c;
    }
}
